//
//  CZLotteryHallController.m
//  A01-CZ彩票
//
//  Created by apple on 15-6-13.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZLotteryHallController.h"
#import "UIImage+Ex.h"
@interface CZLotteryHallController ()
@property (weak, nonatomic) IBOutlet UIBarButtonItem *leftItem;

@property (nonatomic, weak) UIView *coverView;
@property (nonatomic, weak) UIImageView *imgView;
@end

@implementation CZLotteryHallController

//点击活动按钮。弹出图片 和 遮盖的view
- (IBAction)leftClicked:(id)sender {
    //获取keyWindow
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    //1 创建遮盖的view
    UIView *view = [[UIView alloc] init];
    self.coverView = view;
    //把遮盖的view添加到window上
    [window addSubview:view];
    //让遮盖view的大小和屏幕大小一样。并从0，0开始显示
    view.frame = [UIScreen mainScreen].bounds; //self.view.bounds; //[x,y width, height]
    view.backgroundColor = [UIColor blackColor];
    view.alpha = 0.6;
    
    //2 显示图片
    UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"aa"]];
    self.imgView = imgView;
    [window addSubview:imgView];
    
    imgView.center = view.center;
    //3 关闭按钮
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [imgView addSubview:closeBtn];
    [closeBtn setImage:[UIImage imageNamed:@"alphaClose"] forState:UIControlStateNormal];
    //
    [closeBtn sizeToFit];
    
    //点击关闭按钮
    [closeBtn addTarget:self action:@selector(btnClose) forControlEvents:UIControlEventTouchUpInside];
    
    //让imgView能和用户交互
    imgView.userInteractionEnabled = YES;
}

- (void)btnClose{
    //动画的方式  关闭遮盖view
    [UIView animateWithDuration:5.0 animations:^{
        self.coverView.alpha = 0;
        self.imgView.frame = CGRectMake(40, 45, 0, 0);
        [self.imgView.subviews[0] setFrame:CGRectMake(0, 0, 0, 0)];
    } completion:^(BOOL finished) {
        [self.coverView removeFromSuperview];
        [self.imgView removeFromSuperview];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置left的图片
    self.leftItem.image =  [self.leftItem.image originalImage];
    
   
//    //UIBarMetricsDefault  背景图片 在横竖屏都显示
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"NavBar64"] forBarMetrics:UIBarMetricsDefault];
//    //设置标题的颜色
//    [self.navigationController.navigationBar  setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor  whiteColor]}];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
